<template>
  <div class="hospitalDiseasesList pd-20">
    <el-input v-model="param.searchCondition"
              placeholder="请输入名称"
              clearable
              class="w-200"
              @clear="handleQuery" />
    <el-button type="primary"
               @click="handleQuery">查 询</el-button>
    <el-button type="primary"
               @click="handleAdd">新 增</el-button>
    <Table :columns="tableCol"
           :data="tableData"
           stripe
           border
           class="mt-20">
      <template slot-scope="{row,index}"
                slot="action">
        <span @click="handleEdit(row)">编辑</span>
        <span @click="handleDel(row)">删除</span>
      </template>
    </Table>
    <page @getList="_getList"
          :pageTotal="pageTotal"
          ref="page"></page>
    <hospitalDiseasesEdit ref="hospitalDiseasesEdit"
                          @getList="_getList"></hospitalDiseasesEdit>
  </div>
</template>

<script>
  import Page from '@/base/page/page'
  import HospitalDiseasesEdit from './hospitalDiseasesEdit'
  import { mapGetters } from 'vuex'
  export default {
    name: "hospitalDiseasesList",
    data () {
      return {
        tableCol: [
          {
            type: 'index2',
            title: '',
            width: 60,
            render: (h, params) => {
              return h('span', params.index + (this.page.pageIndex) * this.page.pageSize + 1);
            }
          },
          {
            title: '名称',
            key: 'name'
          },
          {
            title: '医院',
            key: 'hospitalName'
          },
          {
            title: '操作',
            slot: 'action',
            align: 'center'
          }
        ],
        tableData: [],
        pageTotal: 0,       //总条数
        param: {
          type: 1,
          searchCondition: ''
        }
      }
    },
    created () {
      this._getList();
    },
    methods: {
      handleQuery(){
        this.page.pageIndex=0
        this._getList()
      },
      handleAdd () {
        this.$refs.hospitalDiseasesEdit.openView();
      },
      handleEdit (row) {
        this.$refs.hospitalDiseasesEdit.openView(Object.assign({}, row));
      },
      handleDel (row) {
        this.$confirm('您确认删除该信息？')
          .then(_ => {
            this.post(this.api.hospitalDiseasesDel.url, { id: row.id }).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('删除成功!');
                this._getList();
              }
            })
          })
          .catch(_ => { });
      },
      _getList () {
        this.post(this.api.hospitalDiseasesList.url, {
          ...this.page,
          ...this.param
        }).then((res) => {
          if (res.data.code === '200') {
            this.tableData = res.data.object;
            this.pageTotal = res.data.totalNum;
          }
        })
      }
    },
    computed: {
      ...mapGetters([
        'page'
      ])
    },
    components: {
      Page,
      HospitalDiseasesEdit
    }
  }
</script>

<style scoped lang="scss" >
</style>
